package job.tracker.domain

import java.util.List;

class User {

	String email
	boolean admin = false
	String firstName = ''
	String lastName = ''
	String password
	List<JobSiteUser> jobSiteUsers

	static hasMany = [
		jobSiteUsers : JobSiteUser
	]
	
	static transients = ['fullName'];

	String getFullName = { return firstName + ' ' + lastName }

	static constraints = {
		email 		(nullable: false, blank: false, email: true, unique: true)
		firstName	(nullable: false, blank: true)
		lastName	(nullable: false, blank: true)
		password	(nullable: true)
		admin		(nullable: false)
	}
	
	static User authenticate(String email) {
		return User.findByEmail(email)
	}
	
	List<JobSite> getJobSites() {
		return this.jobSiteUsers*.jobSite
	}
}